<?php
$srcPath = '../src';

$frameworkPath = $srcPath . '/framework';

require_once $frameworkPath . '/Framework.php';

$framework = new Framework;

$framework->boot();

$mysqliConfig = array(
'schema' => 'oopframeworktest',
'host' => 'localhost',
'user' => 'oopframeworktest',
'pass' => 'password'
);

$mysqli = new MySQLiDBConnection($mysqliConfig['host'], $mysqliConfig['user'], $mysqliConfig['pass'], $mysqliConfig['schema']);

$success = $mysqli->doConnect();

if (!$success)	{
	echo ("error:" . $mysqli->getConnectError());
}

function showQueryInfo(DBConnection $db, $sql)	{
	
	$result = $db->query($sql);
	echo "<pre>";
	$out['sql'] = $result->getSQL();
	$out['duration'] = $result->getDuration();
	$out['is_success'] = $result->isSuccess();
	$out['error number'] = $result->getErrorNumber();
	$out['error message'] = $result->getErrorMessage();
	$out['rows'] = $result->getRowCount();
	$out['affected row count'] = $result->getAffectedRowsCount();
	$out['from count interface'] = count($result);
	$out['field count'] = $result->getFieldCount();
	$out['fields'] = print_r ($result->getFields(), true);
	$out['insert id'] = $result->getLastInsertID();
	
	if (isset($result[1]))	{
		$out['2nd row'] = print_r ($result[1], true);
	}
	
	$out['result as array'] = print_r ($result->getResultArray(), true);
	
	foreach($result as $aRow)	{
		$out['result from for each'][] = print_r($aRow, true);
	}
	
	foreach($out as $key => $msg)	{
		echo $key . ' : ' . print_r($msg, true) . "<br/>\n";
	}
	echo "</pre>";
	echo str_repeat("<br/>", 2);
}


$insertSQL = 'INSERT INTO test_table VALUES (null, "' . substr(md5(microtime()), 10) . '", "'  . substr(md5(microtime()), 10, 10) . '")';
showQueryInfo($mysqli, $insertSQL);

$lastInsertID = $mysqli->getLastInsertID();


$selectSQL = 'SELECT * FROM test_table;';

showQueryInfo($mysqli, $selectSQL);

$deleteSQL = 'DELETE FROM test_table WHERE id = ' . $lastInsertID;
showQueryInfo($mysqli, $deleteSQL);

$mysqli->doDisconnect();

showQueryInfo($mysqli, $selectSQL);
?>